// Copyright (c) 2024, the WwMusic project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package com.springfairy.service.impl;

import com.springfairy.dao.MoodTypeMapper;
import com.springfairy.model.MoodType;
import com.springfairy.service.MoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MoodTypeServiceImpl implements MoodTypeService {

    @Autowired
    private MoodTypeMapper moodTypeMapper;

    @Override
    public MoodType createMoodType(MoodType moodType) {
        moodTypeMapper.insert(moodType);
        return moodType;
    }

    @Override
    public List<MoodType> getAllMoodTypes() {
        return moodTypeMapper.selectList(null);
    }

    @Override
    public void deleteMoodType(int id) {
        int rows = moodTypeMapper.deleteById(id);
        if (rows == 0) {
            throw new RuntimeException("Mood type not found");
        }
    }
}
